<?php

namespace app\cps\controller;

use think\facade\Request;
use app\common\Common;
use app\cps\service\OrderService;

class Order extends Base
{
    private $service;

    public function __construct(OrderService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染订单列表页
    public function index()
    {
        return view();
    }

    // 订单列表
    public function list()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('list')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getOrderList($params);

        return Common::success($data);
    }

    // 链接订单详情统计
    public function linkOrderDetailListSumRecharge()
    {
        $params = Request::param();

        $data = $this->service->linkOrderDetailListSumRecharge($params);

        return Common::success($data);
    }

    // 渲染历史数据页
    public function history()
    {
        return view();
    }

    // 历史数据
    public function data()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('data')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        // $data = $this->service->getHistoryData($params);
        $data = $this->service->getHistoryDataList($params);

        return Common::success($data);
    }

    // 获取历史数据统计
    public function getHistoryDataSum()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('data')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getHistoryDataSum($params);

        return Common::success($data);
    }

    // 渲染订单明细列表页
    public function detailed()
    {
        return view();
    }

    // 订单明细列表
    public function detailedList()
    {
        $params = Request::param();

        $data = $this->service->getOrderDetailedList($params, $this->getUserInfo());

        return Common::success($data);
    }

    // 订单导出
    public function detailedExcel()
    {
        $params = Request::param();

        $this->service->getOrderDetailedExcel($params, $this->getUserInfo());
        return Common::success();
    }

    // 订单列表统计充值
    public function orderListSumRechare()
    {
        $params = Request::param();

        $data = $this->service->orderListSumRechare($params, $this->getUserInfo());

        return Common::success($data);
    }

    // 渲染链接的LTV数据列表页
    public function daily()
    {
        return view();
    }

    // 链接的LTV数据
    public function dailyRechargeDetails()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('daily_recharge_details')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getLinkDailyRechargeDetails($params);

        return Common::success($data);
    }

    // 分销LTV数据
    public function distributionLtvData()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('daily_recharge_details')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getDistributionLtvData($params);

        return Common::success($data);
    }

    // 分销商订单列表
    public function distributionOrderList()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('distribution_order_list')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getDistributionOrderList($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success($data);
    }
}